//
//  TestCalendarViewController.m
//  Demos
//
//  Created by iMac on 2018/3/2.
//  Copyright © 2018年 iMac. All rights reserved.
//

#import "TestCalendarViewController.h"
#import "WDCalendarDateHandler.h"
#import "NSDate+ForCalendar.h"

#import "WDCalendarMonthView.h"
#import "WDCalendarScrollView.h"
#import "WDCalendarCollectionView.h"




@interface TestCalendarViewController ()

@end

@implementation TestCalendarViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self addDismissButton];
    
    
//    WDCalendarMonthView *monthView = [[WDCalendarMonthView alloc] init];
//    [self.view addSubview:monthView];
//    __weak __typeof(monthView)weakMonthView = monthView;
//    __weak __typeof(self)weakSelf = self;
//    monthView.monthSizeChanged = ^(CGSize size) {
//        __strong __typeof(weakMonthView)strongMonthView = weakMonthView;
//        __strong __typeof(weakSelf)strongSelf = weakSelf;
//        if (strongMonthView) {
//            strongMonthView.frame = CGRectMake(0, 200, size.width, size.height);
//            if (strongSelf) {
//                [strongSelf updateViewConstraints];
//            }
//        }
//    };

    
//    WDCalendarScrollView *calendar = [[WDCalendarScrollView alloc] init];
//    calendar.frame = CGRectMake(0, 100, SCREEN_WIDTH, 500);
    WDCalendarCollectionView *calendar = [[WDCalendarCollectionView alloc] initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, 500)];
    
    [self.view addSubview:calendar];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    // NSInteger day = [[NSDate date] getFirstDayWeekForMonth];
//    NSLog(@"day--%ld", day);
    
     // [[WDCalendarDateHandler sharedInstance] numsOfRows];
    NSArray * arr = [[WDCalendarDateHandler sharedInstance] datesOfCurrentCalendarPage:[NSDate date]];
    for (NSDate *date in arr) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyy-MM-dd";
        NSString *dateStr = [formatter stringFromDate:date];
        NSLog(@"---- : %@", dateStr);
    }
    
    
}



#pragma mark -添加dismissButton
- (void)addDismissButton {
    UIButton *dismiss = ({
        UIButton *btn = [[UIButton alloc] init];
        [btn setTitle:@"dismiss" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        CGFloat f = 100;
        btn.frame = CGRectMake(SCREEN_WIDTH - f, SCREEN_HEIGHT - f, f, f);
        [btn setBackgroundColor:[UIColor purpleColor]];
        [btn addTarget:self action:@selector(dismissButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        btn;
    });
    [self.view addSubview:dismiss];
}
- (void)dismissButtonClick:(UIButton *)sender {
    [self dismissViewControllerAnimated:true completion:nil];
}


@end
